// 方法初始化 调用
var config = {
    'os': "wap", //终端 pc /wap
    'domain': "mk12.yangwajia.com", //当前域名  
    'os_adapt': 1, //终端自适应 1-开启 0-不开启
    'pc_domain': "k12.yangwajia.com",
    'wap_domain': "mk12.yangwajia.com",
    'httptohttps': false //是否强制将http转换为https
};
$(function() {
    //根据配置初始化对应的函数
    if (config.os == "wap") {
        wap_allsize()
        wap_common();
        prev_page('yangwajia', $('.logo'), $('.backhome'))
        if (config.os_adapt == 1) {
            page_m_pc(config.domain, config.pc_domain, 1, config.httptohttps)
        }
    } else {
        if (config.os_adapt == 1) {
            page_m_pc(config.domain, config.wap_domain, '', config.httptohttps)
        }
    }
});

// m端专用 尺寸适配各型号手机（无需调用直接引入）
function wap_allsize() {
    (function(win, lib) {
        var doc = win.document;
        var docEl = doc.documentElement;
        var metaEl = doc.querySelector('meta[name="viewport"]');
        var flexibleEl = doc.querySelector('meta[name="flexible"]');
        var dpr = 0;
        var scale = 0;
        var tid;
        var flexible = lib.flexible || (lib.flexible = {});

        if (metaEl) {
            //    console.warn('将根据已有的meta标签来设置缩放比例');
            var match = metaEl.getAttribute('content').match(/initial\-scale=([\d\.]+)/);
            if (match) {
                scale = parseFloat(match[1]);
                dpr = parseInt(1 / scale);
            }
        } else if (flexibleEl) {
            var content = flexibleEl.getAttribute('content');
            if (content) {
                var initialDpr = content.match(/initial\-dpr=([\d\.]+)/);
                var maximumDpr = content.match(/maximum\-dpr=([\d\.]+)/);
                if (initialDpr) {
                    dpr = parseFloat(initialDpr[1]);
                    scale = parseFloat((1 / dpr).toFixed(2));
                }
                if (maximumDpr) {
                    dpr = parseFloat(maximumDpr[1]);
                    scale = parseFloat((1 / dpr).toFixed(2));
                }
            }
        }

        if (!dpr && !scale) {
            var isAndroid = win.navigator.appVersion.match(/android/gi);
            var isIPhone = win.navigator.appVersion.match(/iphone/gi);
            var devicePixelRatio = win.devicePixelRatio;
            if (isIPhone) {
                // iOS下，对于2和3的屏，用2倍的方案，其余的用1倍方案
                if (devicePixelRatio >= 3 && (!dpr || dpr >= 3)) {
                    dpr = 3;
                } else if (devicePixelRatio >= 2 && (!dpr || dpr >= 2)) {
                    dpr = 2;
                } else {
                    dpr = 1;
                }
            } else {
                // 其他设备下，仍旧使用1倍的方案
                dpr = 1;
            }
            scale = 1 / dpr;
        }

        docEl.setAttribute('data-dpr', dpr);
        if (!metaEl) {
            metaEl = doc.createElement('meta');
            metaEl.setAttribute('name', 'viewport');
            metaEl.setAttribute('content', 'initial-scale=' + scale + ', maximum-scale=' + scale + ', minimum-scale=' + scale + ', user-scalable=no');
            if (docEl.firstElementChild) {
                docEl.firstElementChild.appendChild(metaEl);
            } else {
                var wrap = doc.createElement('div');
                wrap.appendChild(metaEl);
                doc.write(wrap.innerHTML);
            }
        }

        function refreshRem() {
            var width = docEl.getBoundingClientRect().width;
            var rem;
            if (width / dpr > 750) {
                rem = 85;
            } else {
                rem = 100 * (width / 750);
            }
            docEl.style.fontSize = rem + 'px';
            flexible.rem = win.rem = rem;
        }

        win.addEventListener('resize', function() {
            clearTimeout(tid);
            tid = setTimeout(refreshRem, 300);
        }, false);
        win.addEventListener('pageshow', function(e) {
            if (e.persisted) {
                clearTimeout(tid);
                tid = setTimeout(refreshRem, 300);
            }
        }, false);
        refreshRem();

        flexible.dpr = win.dpr = dpr;
        flexible.refreshRem = refreshRem;
        flexible.rem2px = function(d) {
            var val = parseFloat(d) * this.rem;
            if (typeof d === 'string' && d.match(/rem$/)) {
                val += 'px';
            }
            return val;
        }
        flexible.px2rem = function(d) {
            var val = parseFloat(d) / this.rem;
            if (typeof d === 'string' && d.match(/px$/)) {
                val += 'rem';
            }
            return val;
        }

    })(window, window['lib'] || (window['lib'] = {}));
}

// --------------------------------------------分割线-------------------------------------------------------------
// 自适配跳转页面(根据打开方式自适配跳转pc端或m端)    用于所有页面
// 使用方法： 
//          调用函数   page_m_pc(yuan,now,mtopc)
//          参数1表示原本页面的路径，参数2表示适配后要跳转的路径，参数3表示是否是从m端适配到pc端（若是则为1，不是则不传）
// 示例
// var yuan_url='m.yangwajia.com'
// var now_url='www.yangwajia.com'
// page_m_pc(yuan_url,now_url,1)

function page_m_pc(yuan, now, mtopc, httptohttps) {
    var sUserAgent = navigator.userAgent.toLowerCase();
    var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
    var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
    var bIsMidp = sUserAgent.match(/midp/i) == "midp";
    var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
    var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
    var bIsAndroid = sUserAgent.match(/android/i) == "android";
    var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
    var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
    var gourl = window.location.href;
    gourl = gourl.replace(yuan, now);
    if (httptohttps == true) {
        gourl = gourl.replace('http://', 'https://');
    }
    if (mtopc == 1) {
        if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {} else {
            window.location.href = gourl;
        }
    } else {
        if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
            window.location.href = gourl;
        }
    }
}

// --------------------------------------------分割线----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

// 懒加载 （所有需要懒加载功能的页面适用）
// 使用方法：
//  页面所有需要懒加载的img标签 加上class='lazyload',data-original='(这里放真实的图片路径)'，原src='(这里放默认图片路径)'
//调用函数：

(function($, window, document, undefined) {
    var $window = $(window);
    $.fn.lazyload = function(options) {
        var elements = this;
        var $container;
        var settings = {
            threshold: 0,
            failure_limit: 0,
            event: "scroll",
            effect: "show",
            container: window,
            data_attribute: "original",
            skip_invisible: true,
            appear: null,
            load: null,
            placeholder: ""
        };

        function update() {
            var counter = 0;
            elements.each(function() {
                var $this = $(this);
                if (settings.skip_invisible && !$this.is(":visible")) {
                    return;
                }
                if ($.abovethetop(this, settings) ||
                    $.leftofbegin(this, settings)) {
                    /* Nothing. */
                } else if (!$.belowthefold(this, settings) &&
                    !$.rightoffold(this, settings)) {
                    $this.trigger("appear");
                    /* if we found an image we'll load, reset the counter */
                    counter = 0;
                } else {
                    if (++counter > settings.failure_limit) {
                        return false;
                    }
                }
            });

        }
        if (options) {
            /* Maintain BC for a couple of versions. */
            if (undefined !== options.failurelimit) {
                options.failure_limit = options.failurelimit;
                delete options.failurelimit;
            }
            if (undefined !== options.effectspeed) {
                options.effect_speed = options.effectspeed;
                delete options.effectspeed;
            }

            $.extend(settings, options);
        }

        /* Cache container as jQuery as object. */
        $container = (settings.container === undefined ||
            settings.container === window) ? $window : $(settings.container);
        /* Fire one scroll event per scroll. Not one scroll event per image. */
        if (0 === settings.event.indexOf("scroll")) {
            $container.bind(settings.event, function() {
                return update();
            });
        }
        this.each(function() {
            var self = this;
            var $self = $(self);
            self.loaded = false;
            /* If no src attribute given use data:uri. */
            if ($self.attr("src") === undefined || $self.attr("src") === false) {
                if ($self.is("img")) {
                    $self.attr("src", settings.placeholder);
                }
            }
            /* When appear is triggered load original image. */
            $self.one("appear", function() {
                if (!this.loaded) {
                    if (settings.appear) {
                        var elements_left = elements.length;
                        settings.appear.call(self, elements_left, settings);
                    }
                    $("<img />")
                        .bind("load", function() {
                            var original = $self.attr("data-" + settings.data_attribute);
                            $self.hide();
                            if ($self.is("img")) {
                                $self.attr("src", original);
                            } else {
                                $self.css("background-image", "url('" + original + "')");
                            }
                            $self[settings.effect](settings.effect_speed);
                            self.loaded = true;
                            /* Remove image from array so it is not looped next time. */
                            var temp = $.grep(elements, function(element) {
                                return !element.loaded;
                            });
                            elements = $(temp);
                            if (settings.load) {
                                var elements_left = elements.length;
                                settings.load.call(self, elements_left, settings);
                            }
                        })
                        .attr("src", $self.attr("data-" + settings.data_attribute));
                }
            });
            /* When wanted event is triggered load original image */
            /* by triggering appear.                              */
            if (0 !== settings.event.indexOf("scroll")) {
                $self.bind(settings.event, function() {
                    if (!self.loaded) {
                        $self.trigger("appear");
                    }
                });
            }
        });
        /* Check if something appears when window is resized. */
        $window.bind("resize", function() {
            update();
        });
        /* With IOS5 force loading images when navigating with back button. */
        /* Non optimal workaround. */
        if ((/(?:iphone|ipod|ipad).*os 5/gi).test(navigator.appVersion)) {
            $window.bind("pageshow", function(event) {
                if (event.originalEvent && event.originalEvent.persisted) {
                    elements.each(function() {
                        $(this).trigger("appear");
                    });
                }
            });
        }
        /* Force initial check if images should appear. */
        $(document).ready(function() {
            update();
        });
        return this;
    };
    /* Convenience methods in jQuery namespace.           */
    /* Use as  $.belowthefold(element, {threshold : 100, container : window}) */
    $.belowthefold = function(element, settings) {
        var fold;
        if (settings.container === undefined || settings.container === window) {
            fold = (window.innerHeight ? window.innerHeight : $window.height()) + $window.scrollTop();
        } else {
            fold = $(settings.container).offset().top + $(settings.container).height();
        }
        return fold <= $(element).offset().top - settings.threshold;
    };

    $.rightoffold = function(element, settings) {
        var fold;
        if (settings.container === undefined || settings.container === window) {
            fold = $window.width() + $window.scrollLeft();
        } else {
            fold = $(settings.container).offset().left + $(settings.container).width();
        }
        return fold <= $(element).offset().left - settings.threshold;
    };
    $.abovethetop = function(element, settings) {
        var fold;
        if (settings.container === undefined || settings.container === window) {
            fold = $window.scrollTop();
        } else {
            fold = $(settings.container).offset().top;
        }
        return fold >= $(element).offset().top + settings.threshold + $(element).height();
    };

    $.leftofbegin = function(element, settings) {
        var fold;
        if (settings.container === undefined || settings.container === window) {
            fold = $window.scrollLeft();
        } else {
            fold = $(settings.container).offset().left;
        }
        return fold >= $(element).offset().left + settings.threshold + $(element).width();
    };
    $.inviewport = function(element, settings) {
        return !$.rightoffold(element, settings) && !$.leftofbegin(element, settings) &&
            !$.belowthefold(element, settings) && !$.abovethetop(element, settings);
    };
    /* Custom selectors for your convenience.   */
    /* Use as $("img:below-the-fold").something() or */
    /* $("img").filter(":below-the-fold").something() which is faster */
    $.extend($.expr[":"], {
        "below-the-fold": function(a) {
            return $.belowthefold(a, {
                threshold: 0
            });
        },
        "above-the-top": function(a) {
            return !$.belowthefold(a, {
                threshold: 0
            });
        },
        "right-of-screen": function(a) {
            return $.rightoffold(a, {
                threshold: 0
            });
        },
        "left-of-screen": function(a) {
            return !$.rightoffold(a, {
                threshold: 0
            });
        },
        "in-viewport": function(a) {
            return $.inviewport(a, {
                threshold: 0
            });
        },
        /* Maintain BC for couple of versions. */
        "above-the-fold": function(a) {
            return !$.belowthefold(a, {
                threshold: 0
            });
        },
        "right-of-fold": function(a) {
            return $.rightoffold(a, {
                threshold: 0
            });
        },
        "left-of-fold": function(a) {
            return !$.rightoffold(a, {
                threshold: 0
            });
        }
    });
})(jQuery, window, document);

$("img.lazyload").lazyload({
    effect: "fadeIn"
});

// --------------------------------------------分割线----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function wap_common() {


    // 顶部菜单栏 各菜单选项如果字数超过4个字则宽度自适应  （适用于此项目m端所有页面）
    // 使用方法：引入即可
    var arr = $('.search_zhankai ul li a')
    for (var i = 0; i < arr.length; i++) {
        if (arr[i].innerHTML.length > 4) {
            $(arr[i]).parent().attr('style', 'width:auto;padding:0 0.4rem')
        }
    }

    // 顶部菜单栏展开或隐藏  本项目（m端）所有页面适用
    // 使用方法：引入即可
    $('.get_more').click(function() {
        $('.search_zhankai').toggle()
        if ($('.search_zhankai').css('display') == 'block') {
            $('body').attr('style', 'overflow:hidden')
        } else {
            $('body').attr('style', 'overflow:scroll')
        }
    })
    $('.search_zhankai').click(function(e) {
        if ($(e.target).is('.search_zhankai')) {
            $(this).hide()
        }
    })

    // --------------------------------------------分割线----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    // 详情页查看更多  本项目（m端）详情页适用
    // 使用方法：引入即可
    var judge = navigator.userAgent;
    if (judge.indexOf('Baidu') > -1 || judge.indexOf('BIDUBrowser') > -1) {
        $('.ckmore').hide()
        $('.zxdetail').attr('style', 'height:auto;max-height:max-content')
    } else {
        if ($('.zxdetail .content').height() > 600) {
            $('.ckmore').show()
            $('.zxdetail').attr('style', 'max-height:16rem')
        }
    }

    $('.more_btn').click(function() {
        $('.zxdetail').attr('style', 'height:auto;max-height:max-content')
        $('.ckmore').hide()
    })

}
// --------------------------------------------分割线----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


// 判断上个页面地址
// 参数说明：searchstr表示上个页面的域名，el_prev表示返回上一页的箭头标签，el_home表示返回首页的标签
function prev_page(searchstr, el_prev, el_home) {
    var referstr = document.referrer;
    if (referstr.indexOf(searchstr) > -1) {
        el_prev.hide()
        el_home.show()
    } else {
        el_prev.show()
        el_home.hide()
    }
}

//-----------------------------------------//

function isWinOrOther() {
    var b = navigator.userAgent.toLowerCase();
    var c = 111;
    var a = window.navigator.platform;
    if (a == "Win32" || a == "Win64" || a == "MacIntel") {
        c = true
    } else {
        c = false
    }
    return c
}

function isBdBox() {
    var a = navigator.userAgent.toLowerCase();
    var c = a.match(/baiduboxapp/i) == "baiduboxapp";
    var b = false;
    if (c) {
        b = true
    } else {
        b = false
    }
    return b
}

function isBdRef() {
    var a = false;
    var b = document.referrer;
    if (b != "" && b != null && b != undefined) {
        b = b.toLowerCase();
        if (b.indexOf("baidu") > 0) {
            a = true
        }
    }
    return a
};
//var nocity="北京,上海,廊坊";var curcity=realip_info.city;function cityindexfo(){if(nocity.indexOf(curcity)==-1||curcity==""){return true}else{return false}};
function isRefAllDisp() {
    var b = false;
    var a = document.referrer;
    if (a != "" && a != null && a != undefined) {
        b = true
    }
    return b
};

function isOneselfRef() {
    var b = false;
    var a = document.referrer;
    if (a != "" && a != null && a != undefined) {
        a = a.toLowerCase();
        if (a.indexOf("mk12.yangwajia.com") > -1) {
            b = true
        }
    }
    return b
};
var isBdRef = isBdRef(),
    isBox = isBdBox(),
    iswin = isWinOrOther(),
    isRefAall = isRefAllDisp(),
    isOneselfRE = isOneselfRef();

function ywj12_detail1() {
    if (!iswin && isRefAall) {
        /**ID:u6642280 160**/
        document.writeln("<script type=\'text/javascript\' src=\'//ssdatas.k12kc.com/source/g/common/b_aa_xq_qdh.js\'></script>");
    }
}

function ywj12_jg_80() {
    /**ID:u6642278 80**/
    if (!iswin) {
        document.writeln("<script type=\'text/javascript\' src=\'//ssdatas.k12kc.com/common/ni/production/h/h/exxj_k.js\'></script>");
    }
}

function ywj12_wtj_147() {
    if (!iswin && isRefAall && !isOneselfRE) {
        /****ID:u6642291  *****/
        document.writeln("<script type=\'text/javascript\' src=\'//ssdatas.k12kc.com/source/i-dcc/static/zssl-m.js\'></script>");
    }
}